package study.mybatis.springboot.support.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Plugin;
import org.apache.ibatis.plugin.Signature;
import study.mybatis.springboot.support.utils.PluginUtils;

import java.sql.Statement;
import java.util.Properties;

@Slf4j
@Intercepts({
        @Signature(type = ResultSetHandler.class,
                method = "handleResultSets",
                args={Statement.class})
})
public class ResultSetInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        PluginUtils.printInvocation(invocation);

        Object result = invocation.proceed();
        return result;
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
